Ext.define('appmod.controller.resources.Module', {
    extend: 'Ext.app.Controller',

	models: [

	],
	
    stores: [

	],
    

    refs: [

	],

    views: [
    ],
	

    init: function() {
		var me = this;
    	this.control({
			
			'moduledashboard': {
			    moduleDelete:me.deleteModule
			}
								
    	});

    },
	

	/**
	 * defined and binding store --
	 */
	onLaunch:function() {


	},

	deleteModule:function(grid , options) {
		var me = this;
		var store = grid.getStore();
		var rec = grid.getStore().getAt(options.rowIndex);
		Ext.MessageBox.confirm('确认', '删除模块时，会连同相关的资源和权限均被彻底删除，不能恢重。确定删除: "'+rec.get('name')+'"?',function() {
			me.deleteLoadedModules(me , grid, rec);
		}, me);

	},
	
	deleteLoadedModules:function(me , grid, removedRecord) {

		var jsonData = [];
		jsonData.push( removedRecord.getId() );

		// --- update record using ajax
		try {

			Ext.Ajax.request({
				url: '../../data/resource/resources/submit_deleteLoadedModules.json',
				method:'post',
				params:{
					'jsonData':Ext.encode(jsonData)
				},
				success: function(response, opts) {

					 var obj = Ext.decode(response.responseText);
					 
					 // --- popup message ---
					Ext.MessageBox.show({
        				title: "提示",
        				msg: obj.msg,
        				buttons: Ext.MessageBox.OK,
        				icon: Ext.MessageBox.WARNING
       				});
					
					// --- reload ---
					

				},
				failure: function(response, opts) {
				
				}
			});

			
		} catch (e) {
			alert(e);
		}		

	}
	

	
});